﻿//-----------------------------------------------------------------------
// <copyright file="PaginationWithRepeater.aspx.cs" company="CMSN Software">
//    Copyright © 2011  CMSN Software
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see http://www.gnu.org/licenses.
// </copyright>
//-----------------------------------------------------------------------

namespace CMSN.Software.Tutorials.HowToUsePaginationWithRepeater
{
    using System;
    using System.Data;
    using System.Globalization;

    /// <summary>
    /// Sample page to show pagination functionality
    /// </summary>
    public partial class PaginationWithRepeater : System.Web.UI.Page
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // set data source to the pagination control
            this.RepeaterCustomPagination.DataSource = SampleData().Tables[0].DefaultView;

            // set the repeater control to be paged.
            this.RepeaterCustomPagination.RepeaterControl = PaginatingRepeater;

            // set the pagination size (number of records per page).
            this.RepeaterCustomPagination.PaginationSize = 10;

            // number of pagination points.
            this.RepeaterCustomPagination.PaginationPointsCount = 3;

            // display first and last links. (default false)  
            this.RepeaterCustomPagination.ShowFirstLast = true;

            // selected page style.
            this.RepeaterCustomPagination.SelectedPageCssClass = "selected-page";

            // pagination point style
            this.RepeaterCustomPagination.PaginationPointCssClass = "pagination-point";

            // navigation links style
            this.RepeaterCustomPagination.NavigationCssClass = "pagination-point";
        }

        /// <summary>
        /// Handles the PreRender event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // set the pagination status label text.
            this.PaginationDisplayText.Text = "Showing " + RepeaterCustomPagination.CurrentPageText + " of " + RepeaterCustomPagination.Count;
        }

        /// <summary>
        /// Sample method to create dummy data.
        /// </summary>
        /// <returns>dummy dataset</returns>
        private static DataSet SampleData()
        {
            DataSet sampleDataSet = new DataSet();
            sampleDataSet.Locale = CultureInfo.InvariantCulture;
            DataTable sampleDataTable = sampleDataSet.Tables.Add("SampleData");

            sampleDataTable.Columns.Add("FirstColumn", typeof(string));
            sampleDataTable.Columns.Add("SeconfColumn", typeof(string));
            DataRow sampleDataRow;
            for (int i = 1; i <= 49; i++)
            {
                sampleDataRow = sampleDataTable.NewRow();
                sampleDataRow["FirstColumn"] = "Cell1: " + i.ToString(CultureInfo.CurrentCulture);
                sampleDataRow["SeconfColumn"] = "Cell2: " + i.ToString(CultureInfo.CurrentCulture);
                sampleDataTable.Rows.Add(sampleDataRow);
            }

            return sampleDataSet;
        }
    }
}